/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cgi.ndk.wf.service;

import com.cgi.ndk.wf.bp.BPService;
import com.cgi.ndk.wf.generated.endToEndProcessOnly.EndToEndProcessOnlyResponse;
import com.cgi.ndk.wf.generated.endToEndTest.EndToEndTestResponse;
import com.cgi.ndk.wf.generated.humanTaskService.CompleteResponse;
import com.cgi.ndk.wf.generated.humanTaskService.LoadTaskResponse;
import com.cgi.ndk.wf.generated.humanTaskService.ReleaseResponse;
import com.cgi.ndk.wf.generated.humanTaskService.SimpleQueryResponse;
import com.cgi.ndk.wf.generated.humanTaskService.StartResponse;
import com.cgi.ndk.wf.generated.instanceManagementService.InstanceInfoType;
import com.cgi.ndk.wf.generated.instanceManagementService.PaginatedInstanceList;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;

/**
 *
 * @author kovalcikm
 */
@Service
public class TaskServiceBP {

    @Autowired
    private BPService bpService;

    public PaginatedInstanceList getInstances(Integer page, Integer limit) {
        return bpService.getInstances(page, limit);
    }

    public InstanceInfoType getAutomaticTask(long id) {
        return bpService.getAutomaticTask(id);
    }

    public SimpleQueryResponse getHumanTasks(Integer page, Integer limit, String dateString) throws Exception {
        XMLGregorianCalendar xmlGregorianCalendar = null;
        if (dateString != null) {
            Date date;
            SimpleDateFormat simpleDateFormat;
            GregorianCalendar gregorianCalendar;;

            simpleDateFormat = new SimpleDateFormat(DateTimeFormat.ISO.DATE.toString());
            date = simpleDateFormat.parse(dateString);
            gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
            gregorianCalendar.setTime(date);
            xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
        }
        return bpService.getHumanTasks(page, limit, xmlGregorianCalendar);

    }

    public StartResponse reserve(String id) {
        return bpService.reserve(id);
    }

    public LoadTaskResponse load(String id) {
        return bpService.load(id);
    }

    public CompleteResponse complete(String id) {
        return bpService.complete(id);
    }

    public EndToEndProcessOnlyResponse endToEndProcessOnly(String id) {
        return bpService.endToEndProcessOnly(id);
    }

    public EndToEndTestResponse endToEndTest(String id) {
        return bpService.endToEndTest(id);
    }

    public ReleaseResponse release(String id) {
        return bpService.release(id);
    }

}
